import 'package:flutter/material.dart';
import 'package:osc/common/MyTextStyle.dart';
import 'package:osc/models/entity/osc_search_result_entity.dart';
import 'package:osc/res/dimens.dart';
import 'package:osc/ui/pages/project/project_detail_page.dart';
import 'package:osc/utils/navigator_util.dart';

import '../image_loader.dart';

class OscSearchSoftWidget extends StatelessWidget {
  final OscSearchArticle software;

  const OscSearchSoftWidget({Key key, this.software}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: (){
        NavigatorUtil.pushPage(context, ProjectDetailPage(id: software.oscId,));
      },
      child: Container(
        color: Colors.white,
        padding: EdgeInsets.all(Dimens.gap_activity_horizontal),
        child: Row(
          children: <Widget>[
            Padding(
              padding: EdgeInsets.only(right: Dimens.gap_activity_horizontal),
              child: SizedBox(
                width: Dimens.view_item_icon_height_biggest,
                child: ImageLoader(url: software.softwareLogo, errorImageName: "logo_software_default",),
              ),
            ),
            Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Text(software.title, style: MyTextStyle.LIST_TITLE,),
                    buildDescription(software.desc),
                  ],
                )
            ),
          ],
        ),
      ),
    );
  }

  buildDescription(String msg){
    return Padding(
      padding: EdgeInsets.only(top: Dimens.gap_view_normal),
      child: Text(
        msg,
        style: TextStyle(
            color: Colors.black54,
            fontSize: Dimens.font_sp10
        ),
        maxLines: 2,
        softWrap: true,
        overflow: TextOverflow.ellipsis,
      ),
    );
  }
}
